package com.example.aigc_education.integration.processor.v1.async;

import com.example.aigc_education.integration.emuns.CozeAsyncWorkflow;
import com.example.aigc_education.integration.processor.v1.CozeAsyncWFProcessor;
import com.example.aigc_education.integration.request.CozeRequest;
import com.example.aigc_education.integration.request.params.v1.CozeWebSearchParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CozeAsyncWebSearchProcessor extends CozeAsyncWFProcessor<CozeWebSearchParam> {

    @Override
    public CozeAsyncWorkflow workflowType() {
        return CozeAsyncWorkflow.WEB_SEARCH;
    }

    @Override
    protected String workflowId() {
        return CozeAsyncWorkflow.WEB_SEARCH.getWorkflowId();
    }


    @Override
    protected boolean isParamValid(CozeRequest<CozeWebSearchParam> request) {
        //参数校验
        CozeWebSearchParam parameters = request.getParameters();
        if (parameters == null) {
            log.error("参数为空");
            return false;
        }

        // 校验 subtopic，如果存在则进行校验
        if (parameters.getSubtopic() != null && parameters.getSubtopic().trim().isEmpty()) {
            log.error("子主题不能为空");
            return false;
        }

        return true;
    }

    @Override
    protected CozeRequest<CozeWebSearchParam> buildRequest(CozeAsyncPlanRequest request) {
        CozeWebSearchParam param = new CozeWebSearchParam();
        param.setSubtopic(request.getSubtopic());
        CozeRequest<CozeWebSearchParam> cozeRequest = new CozeRequest<>();
        cozeRequest.setParameters(param);
        return cozeRequest;
    }
}
